﻿@using Enter.Admin.Entities
@using Enter.Admin.Utils
@using Enter.Admin.Enums
@model Employ
@{
    ViewData["Title"] = "用户管理 - " + (Model.Id == 0 ? "创建" : "编辑");
}
@section Styles {
    <link href="~/plugins/bootstrap-select/dist/css/bootstrap-select.min.css" rel="stylesheet" />
}
@section Scripts {
    <script src="~/plugins/bootstrap-select/dist/js/bootstrap-select.min.js"></script>
    <script src="~/plugins/parsleyjs/dist/parsley.min.js"></script>
    <script src="~/plugins/parsleyjs/dist/i18n/zh_cn.extra.js"></script>
    <script src="~/plugins/parsleyjs/dist/i18n/zh_cn.js"></script>
    <script>
        var edit = function () {
            if (!$('#form-home-edit').parsley().validate()) return;
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "@(Model.Id == 0 ? Url.Action("Create", "User") : Url.Action("Edit", "User"))",// ,new {id = Model.Id }
                data: $("#form-home-edit").serialize(),
                success: function (result) {
                    if (result.Success) {
                        window.location.href = "@Url.Action("Index", "User")";
                    } else {
                        show_alert('warning', result.Message)
                    }
                },
                error: function (e) {
                    show_alert('error', '网络异常.')
                }
            });
        }
        $(document).ready(function () {
            $('.selectpicker').selectpicker('render');

            $('#form-save-button').click(function () {
                edit();
            })
        });
    </script>
}
<h1></h1>
<div>
    <form class="row" asp-action="Edit" id="form-home-edit">
        <div class="col-md-6">
            <!-- begin panel -->
            <div class="panel panel-inverse">
                <!-- begin panel-heading -->
                <div class="panel-heading">
                    <h4 class="panel-title">用户管理 - @(Model.Id == 0 ? "创建" : "编辑")</h4>
                </div>
                <!-- end panel-heading -->
                <!-- begin panel-body -->
                <div class="panel-body">
                    @if (Model.Id > 0)
                    {
                        <div class="form-group">
                            <label class="col-form-label">序号</label>
                            <input asp-for="Id" class="form-control" readonly="readonly"/>
                        </div>
                    }
                    <div class="form-group">
                        <label>角色</label>
                        @Html.DropDownList("RoleId", (List<SelectListItem>)ViewData["RoleSelectList"], new { @class = "form-control selectpicker", @data_live_search = "true", @data_style = "btn-primary" })
                    </div>
                    <div class="form-group">
                        <label class="col-form-label text-danger">用户名</label>
                        @if (Model.Id > 0)
                        {
                            <input asp-for="UserName" class="form-control"  readonly="readonly"/>
                        }
                        else
                        {
                            <input asp-for="UserName" class="form-control" data-parsley-required="true" data-parsley-minlength="2" />
                        }                        
                    </div>
                    <div class="form-group">
                        <label class="col-form-label text-danger">密码</label>
                        @if (Model.Id > 0)
                        {
                            <input type="password" id="Password" name="Password" placeholder="密码为空则不修改" class="form-control" data-parsley-minlength="6" />
                        }
                        else
                        {
                            <input type="password" id="Password" name="Password" class="form-control" data-parsley-required="true" data-parsley-minlength="6" />
                        }
                    </div>                    
                    <div class="form-group">
                        <label class="col-form-label text-danger">姓名</label>
                        <input asp-for="TrueName" class="form-control" data-parsley-required="true" />
                    </div>
                    <div class="form-group">
                        <label class="col-form-label">邮箱</label>
                        <input asp-for="Email" class="form-control" data-parsley-type="email" />
                    </div>
                    <div class="form-group">
                        <label class="col-form-label">手机号码</label>
                        <input asp-for="Phone" class="form-control" data-parsley-pattern="/^1[0-9]{10}$/" data-parsley-pattern-message="请输入正确的手机号码" />
                    </div>                    
                     <div class="form-group">
                        <label class="col-form-label text-danger">状态</label>
                        @Html.DropDownListFor(model => model.State, Tools.EnumList<EnumEmployState>(), new { @class = "form-control selectpicker", @data_live_search = "true", @data_style = "btn-primary" })
                    </div>
                </div>
                <!-- end panel-body -->
            </div>
            <!-- end panel -->
        </div>
    </form>
</div>

<div class="row">
    <input id="form-save-button" type="button" class="btn btn-primary" value="保存" />
    <a style="margin-left: 10px;" class="btn btn-primary" asp-action="Index">返回列表</a>
</div>

